package com.easy.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.easy.demo.entity.User;
import com.easy.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/crud")
public class CRUD {

        @Autowired
        UserMapper userMapper;

        @RequestMapping(value = {"/selectALLUser"},method = RequestMethod.GET)
        public List<User> ListUser(){
            return userMapper.ListUser();
        }

        @RequestMapping(value={"/selectUserById"}, method=RequestMethod.GET)
        public User selectUserById(String id){
            User user = userMapper.selectUserById(Integer.parseInt(id));
            return user;
        }

        @RequestMapping(value={"/selectUserByName"}, method=RequestMethod.GET)
        public List<User> selectUserByName(String name){
            return userMapper.selectUserByName(name);
        }

        @RequestMapping(value={"/addUser"}, method=RequestMethod.POST)
        public void addUser(User user){
            userMapper.addUser(user);
        }

        @RequestMapping(value={"/updateUser"}, method=RequestMethod.POST)
        public void updateUser(User user){
            userMapper.updateUser(user);
        }

        @RequestMapping(value={"/deleteUser"}, method=RequestMethod.DELETE)
        public void deleteUser(String id){
            userMapper.deleteUser(Integer.parseInt(id));

        }
    }

